package com.ncloud.system.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.system.entity.Company;

@Mapper
public interface CompanyMapper{

	@Select("SELECT company_id, company_name, company_addr, contact_person, contact_phone, state, create_user,"
			+ "date_format(create_date, '%Y-%m-%d %H:%i:%s' ) as create_date, "
			+ "update_user,date_format(update_date, '%Y-%m-%d %H:%i:%s' ) as update_date, remarks FROM sys_company "
			+ "where #{state}=2 or state = #{state}")
	@Results({
		@Result(column="company_id",property="companyId"),@Result(column="company_name",property="companyName"),
		@Result(column="company_addr",property="companyAddr"),@Result(column="contact_person",property="contactPerson"),
		@Result(column="contact_phone",property="contactPhone"),@Result(column="state",property="state"),
		@Result(column="create_user",property="createUser"),
		@Result(column="create_date",property="createDate"),@Result(column="update_user",property="updateUser"),
		@Result(column="update_date",property="updateDate"),@Result(column="remarks",property="remarks")})
	List<Company> getCompanyInfo(Integer state);
	@Select("SELECT company_id, company_name, company_addr, contact_person, contact_phone, state, create_user,"
			+ "date_format(create_date, '%Y-%m-%d %H:%i:%s' ) as create_date, "
			+ "update_user,date_format(update_date, '%Y-%m-%d %H:%i:%s' ) as update_date, remarks FROM sys_company "
			+ "WHERE company_id = #{companyId}")
	@Results({
		@Result(column="company_id",property="companyId"),@Result(column="company_name",property="companyName"),
		@Result(column="company_addr",property="companyAddr"),@Result(column="contact_person",property="contactPerson"),
		@Result(column="contact_phone",property="contactPhone"),@Result(column="state",property="state"),
		@Result(column="create_user",property="createUser"),
		@Result(column="create_date",property="createDate"),@Result(column="update_user",property="updateUser"),
		@Result(column="update_date",property="updateDate"),@Result(column="remarks",property="remarks")})
	List<Company> getCompanyById(Integer companyId);

	@Insert(value = "INSERT INTO sys_company (company_id, company_name, company_addr, contact_person, contact_phone,state, create_user, create_date, update_user, update_date, remarks) "
			+ "values(#{companyId},#{companyName},#{companyAddr},#{contactPerson},#{contactPhone},#{state},#{createUser},#{createDate},#{updateUser},#{updateDate},#{remarks})")
    public int insertCompany(Company company);
	
	@Update(value = "UPDATE sys_company SET company_name = #{companyName}, company_addr = #{companyAddr}, contact_person = #{contactPerson}, contact_phone = #{contactPhone}, "
			+ "update_user = #{updateUser}, update_date = #{updateDate}, remarks = #{remarks} WHERE company_id = #{companyId}")
    public int updateCompany(Company company);
	
	@Update(value = "UPDATE sys_company SET state = #{state},update_user = #{updateUser}, update_date = #{updateDate} WHERE company_id = #{companyId}")
    public int updateCompanyState(Company company);
	
	@Delete(value = "delete from sys_company WHERE company_id = #{companyId}")
    public int deleteCompany(Integer companyId);
}
